<template>
  <div id="index">
    <input type="text" name="nameList" v-model="inputtext">
    <ul>
      <li v-if="inputtext" v-for="(value, index) in inputtext.split('，')" v-bind:key="value">
        {{ index + 1 }}号玩家： {{ value }}
      </li>
    </ul>
    <button @click="init">初始化</button>
    <router-view/>
  </div>
</template>

<script>
import Axios from '../../utils/request'

export default {
  name: 'home',
  data () {
    return {
      inputtext: ''
    }
  },
  methods: {
    async init () {
      const param = {nameList: this.inputtext}
      // axios请求是异步的，使用await同步执行
      let x = await Axios.post('api/init', param)
      if (!x.data.success) {
        alert('出错：' + x.data.msg)
      } else {
        this.$router.push('/index')
      }
    }
  }
}
</script>

<style>
ul {
  list-style: none;
}
</style>
